package com.linlin.song.bigwork.web.customer;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.linlin.song.bigwork.entity.Product;
import com.linlin.song.bigwork.service.ProductPictureService;
import com.linlin.song.bigwork.service.ProductService;

/**
 * Servlet implementation class ProductServlet
 */
@WebServlet("/product/detail")
public class ProductDetailServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private ProductService productService  = new ProductService();
	private ProductPictureService productPictureService  = new ProductPictureService();

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	    String idStr = request.getParameter("id");
	    Long id = Long.valueOf(idStr);
	    Product product = this.productService.findById(id);
	    request.setAttribute("bean", product);
	    try {
            request.setAttribute("pics", productPictureService.findByProductId(id));
        } catch (SQLException e) {
            e.printStackTrace();
        }
	    request.getRequestDispatcher("/WEB-INF/view/product_detail.jsp").forward(request, response);
	}
}
